home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Amiga-E / E_v3.2a / Src / Utils / Watch.e < prev   
Text File  |  1992-09-02  |  2KB  |  49 lines

  1. /* Watch a file by notification
  2.  
  3. pops up a requester when a file gets modified.
  4. USAGE: watch <file>
  5. EXAMPLE: run >NIL: watch >NIL: s:startup-sequence 
  6.  
  7. needs v37
  8.  
  9. simply "watches" a file, using the new notification system
  10. of kick2.0. note: does not _prevent_ files from being modified,
  11. just tells you. usefull, for example, if you're installing a new
  12. software package, and you want to know wether the installer
  13. does something funny to your startup-sequence or user-startup.
  14.  
  15. note that the only way to stop watching is asctually modifying
  16. the file. (or rebooting :-)
  17.  
  18. */
  19.  
  20. OPT OSVERSION=37
  21.  
  22. MODULE 'dos/notify'
  23.  
  24. PROC main()                       /* make sure file is there: else we'll */
  25.   DEF nreq:PTR TO notifyrequest,sig,task
  26.   IF (FileLength(arg)=-1) OR (arg[0]=0)     /* never be notified */
  27.     WriteF('file "\s" does not exist\n',arg)
  28.     CleanUp(10)
  29.   ENDIF
  30.   nreq:=New(SIZEOF notifyrequest)     /* memory is cleared */
  31.   IF nreq=NIL THEN RETURN 20
  32.   sig:=AllocSignal(-1)                /* we want to be signalled */
  33.   IF sig=-1 THEN RETURN 10
  34.   task:=FindTask(0)
  35.   nreq.name:=arg                      /* fill in structure */
  36.   nreq.flags:=NRF_SEND_SIGNAL
  37.   nreq.port:=task                     /* union port/task */
  38.   nreq.signalnum:=sig
  39.   IF StartNotify(nreq)
  40.     WriteF('Now watching: "\s"\n',arg)
  41.     Wait(Shl(1,sig))
  42.     EasyRequestArgs(0,[20,0,0,'File "\s" modified!','Damn!'],0,[arg])
  43.     EndNotify(nreq)
  44.   ELSE
  45.     WriteF('Could not watch "\s".\n',arg)
  46.   ENDIF
  47.   FreeSignal(sig)
  48. ENDPROC
  49.